package com.exercise.widgets.spinner

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.exercise.widgets.databinding.ItemSpinnerBinding

class MySpinnerAdapter<T>(
    private val data: MutableList<T> = mutableListOf()
) : BaseAdapter() {
    override fun getCount(): Int {
        return data.size
    }

    override fun getItem(position: Int): T {
        return data[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
       return ItemSpinnerBinding.inflate(LayoutInflater.from(parent?.context), parent, false).apply {
            tvData.text = getItem(position).toString()
        }.root
    }

}